package com.zhoujing.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.widget.ImageView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import com.android.volley.toolbox.ImageLoader.ImageListener;
import com.zhongxin.wymovieticket.R;

public class ImageDownLoadUtils {

	public ImageDownLoadUtils() {
		// TODO Auto-generated constructor stub
	}

	public static void downLoadImage(String path, RequestQueue queue,
			Context context, ImageView imageView) {
		int maxSize = ((ActivityManager) context
				.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass() / 8;
		final LruCache<String, Bitmap> lruCache = new LruCache<String, Bitmap>(
				maxSize) {
			@Override
			protected int sizeOf(String key, Bitmap value) {
				// TODO Auto-generated method stub
				return value.getRowBytes() * value.getHeight();
			}
		};
		ImageCache cache = new ImageCache() {

			@Override
			public void putBitmap(String url, Bitmap bitmap) {
				// TODO Auto-generated method stub
				lruCache.put(url, bitmap);
			}

			@Override
			public Bitmap getBitmap(String url) {
				// TODO Auto-generated method stub
				return lruCache.get(url);
			}
		};
		ImageLoader loader = new ImageLoader(queue, cache);
		ImageListener imageListener = ImageLoader.getImageListener(imageView,
				R.drawable.ic_launcher, R.drawable.ic_launcher);
		loader.get(path, imageListener, 100, 80);
	}
}
